
<?php foreach ($incoming_events as $value) { ?>

<div class="wall-post large-12 columns">
	<div class="wall-head large-12 column" style="padding:0;">
		<div class="wall-head large-12 column" style="background:#F5F5F5;">
			<div class="eventnow medium-12 columns">
				<a href="" style="font-size:.9rem;"><?= $value->title; ?></a>
				<p><small><i class="fa fa-clock-o"> <abbr class="timeago" title="<?= $value->date_created ?>"></abbr></i></small></p></i></small></p>
			</div>
		</div>
	</div>
	<div class="wall-content large-12 column" style="background:#F5F5F5;">
		<p><?= $value->content; ?></p>
	</div>
	<div class="meetupinfo large-12 column" style="border:none !important;">
		<h5>Posted by: <span><a target= "_blank" href="<?= BASE_URI ?>profile?bhd=<?=$value->creator_id ?>"><?= $value->fname.' '.$value->lname ?></a></span> </h5>
		<h5>Title: <span><a><?=$value->title?></a></span> </h5>
		<h5>When: <span><?php 
						$date = new DateTime($value->when,new DateTimeZone("Asia/Hong_Kong")); 
						echo $date->format('M d, Y h:m A')	;
					?></span></h5>
		<h5>Venue: <span><?=$value->venue?></span></h5>
	</div>
	<div class="likeshare large-12 column">
		<div class="medium-6 large-6 column">
			<ul class="inline-list">
				<li><a class="btnComing" event_id="<?=$value->id?>" >Going</a></li>
				<li><a class="btnMaybe" event_id="<?=$value->id?>" >Maybe</a></li>
				<li><a class="btnReport" event_id="<?=$value->id?>" >Report</a></li>
			</ul>
		</div>
		<div class="text-right medium-4 large-4 column">
						<p id="coming_<?=$value->id?>"class="people_coming" event_id = "<?=$value->id?>">
				<?= UserEventStatus::find(array(
					"conditions"=>"status = 'coming' and event_id = ?0",
					"bind"=>array(0=>$value->id)
				))->count() ?> people coming</p>
		</div>
	</div>
</div>

<?php } ?>

<script type="text/javascript">
	function updateEvent(event_id,status){
		var params = {};
		params.event_id = event_id;
		params.status = status;

		return $.ajax({
			url: URL + 'events/insertstatus',
			data : params,
			type: 'post',
			dataType: 'json'
		});
	}

	$(document).ready(function(){

		jQuery("abbr.timeago").timeago();

		$(document).on('click','.btnComing',function(){
			var event_id = $(this).attr('event_id');
			var status = "coming";

			updateEvent(event_id,status).done(function(result){
				if(result.status == true)
				{
					var content = '<p id="coming_'+ event_id + '"class="people_coming" event_id = "'+ event_id + '">'+ result.total_coming + ' people coming</p>'
						$('#coming_' + event_id).html(content);
				}
			});
		});

		$(document).on('click','.btnMaybe',function(){
			var event_id = $(this).attr('event_id');
			var status = "maybe";

			updateEvent(event_id,status).done(function(result){
				if(result.status == true)
				{
					var content = '<p id="coming_'+ event_id + '"class="people_coming" event_id = "'+ event_id + '">'+ result.total_coming + ' people coming</p>'
						$('#coming_' + event_id).html(content);
				}
			});
		});
	});
</script>